package org.edu.modules.sxjy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.edu.modules.sxjy.entity.VeBanji;
import org.edu.modules.sxjy.entity.VeCommon;
import org.edu.modules.sxjy.entity.VeStudent;
import org.edu.modules.sxjy.feign.VeCommonClient;
import org.edu.modules.sxjy.mapper.VeStudentMapper;
import org.edu.modules.sxjy.service.IVeStudentService;
import org.edu.modules.sxjy.vo.VeStudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VeStudentServiceImpl
        extends ServiceImpl<VeStudentMapper, VeStudent>
        implements IVeStudentService
{
    @Autowired
    VeStudentMapper veStudentMapper;
    @Autowired
    VeCommonClient veCommonClient;
    @Autowired
    IVeStudentService veStudentService;

    public List<VeStudent> lists()
    {
        return this.veStudentMapper.lists();
    }

    public List<VeStudentVo> selectAll(VeStudentVo veStudentVo, Integer startLine, Integer pageSize, VeCommon veCommon)
    {
        return this.veStudentMapper.selectAll(veStudentVo, startLine, pageSize, veCommon);
    }

    public int getSumPage(VeStudentVo veStudentVo, VeCommon veCommon)
    {
        return this.veStudentMapper.getSumPage(veStudentVo, veCommon);
    }

    public VeStudent getListByXh(String xh)
    {
        return this.veStudentMapper.getListByXh(xh);
    }

    public VeStudent getStuId(int userId)
    {
        return this.veStudentMapper.getStuId(userId);
    }

    public List<VeStudentVo> getStuByUserId(VeStudentVo veStudentVo, Integer userId)
    {
        List<VeStudentVo> veStudentVoList = new ArrayList();
        List<VeBanji> veBanjiList = this.veStudentMapper.getBjList();
        List<Integer> banjiIdList = new ArrayList();
        for (VeBanji veBanji : veBanjiList) {
            if (veBanji.getBzrUserId() == userId.intValue()) {
                banjiIdList.add(Integer.valueOf(veBanji.getId()));
            }
        }
        //lbh 2024/07/31 Object >> List<Integer>
        List<Integer> banjiIdLists = (List)banjiIdList.stream().distinct().collect(Collectors.toList());

        List<VeStudent> veStudentList = this.veStudentService.list();
        for (Iterator localIterator2 = veStudentList.iterator(); localIterator2.hasNext();)
        {
            //lbh 2024/07/31 veStudent >> VeStudent veStudent
            VeStudent veStudent = (VeStudent)localIterator2.next();
            //lbh 2024/07/31 (List)banjiIdLists >> banjiIdLists
            for (Integer bjIdList : banjiIdLists)
            {
                VeStudentVo veStudentVos = new VeStudentVo();
                if (veStudent.getBjId() == bjIdList.intValue()) {
                    if ((veStudentVo.getXm() != null) && (veStudentVo.getXm() != ""))
                    {
                        if (veStudent.getXm().contains(veStudentVo.getXm()))
                        {
                            veStudentVos.setId(veStudent.getId());
                            veStudentVos.setXm(veStudent.getXm());
                            veStudentVos.setXh(veStudent.getXh());
                            veStudentVoList.add(veStudentVos);
                        }
                    }
                    else if ((veStudentVo.getXh() != null) && (veStudentVo.getXh() != ""))
                    {
                        if (veStudent.getXh().contains(veStudentVo.getXh()))
                        {
                            veStudentVos.setId(veStudent.getId());
                            veStudentVos.setXm(veStudent.getXm());
                            veStudentVos.setXh(veStudent.getXh());
                            veStudentVoList.add(veStudentVos);
                        }
                    }
                    else
                    {
                        veStudentVos.setId(veStudent.getId());
                        veStudentVos.setXm(veStudent.getXm());
                        veStudentVos.setXh(veStudent.getXh());
                        veStudentVoList.add(veStudentVos);
                    }
                }
            }
        }
        VeStudent veStudent;
        return veStudentVoList;
    }
}
